﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SWSoft.Framework;
using MediSIIM.BizComponent.ZheJiangSYKT;
using Tools.Unity;

namespace ZheJiangSYKT
{
    public class TradeInfo : DBVisitor<Entry>
    {

        public bool YBCall(ZheJiangSYKTTradeParam parms)
        {
            var retcode = YiBaoJKDLL.YbCall(parms.TradeTypeNo, parms.InData, FormZheJiangSYKT.BXLBXX.YBYYDM, ref parms.OutData);
            if (retcode < 0)
            {
                return false;
            }
            return true;
        }

        public string gettradestatus(string status)
        {
            switch (status)
            {
                case "0": return "已结算";
                case "1": return "已确认";
                case "2": return "已退费";
                case "9":
                default: return "无记录";
            }
        }

        //门诊结算，门诊退费，住院结算，住院退费、住院登记
        /// <summary>
        /// 门诊结算
        /// </summary>
        public void TradeCheck(ListView listView1, string tradeid)
        {
            var list = new List<ListViewItem>();
            foreach (ListViewItem listitem in listView1.CheckedItems)
            {
                var item = listitem.Tag as Entry;
                var indata = "$$" +
                 "1" + "~" +//是否有社会保障卡
                 item["YBDKXX"] + "~" +//社会保障卡信息
                 "" + "~" +//预留1
                 "" + "~" +//预留2
                 tradeid + "~" +//待查询用户交易类型号
                 item["YBDJHM"] + "" +//待查询的用户序列号
                 "$$";
                var callparam = new ZheJiangSYKTTradeParam(9216, indata);
                YBCall(callparam);
                var strs = callparam.OutData.Split('~');
                if (strs[0] == "0")
                {
                    item["YBJYHM"] = strs[4];
                    var viewitem = new ListViewItem(strs[4]);//交易流水号
                    viewitem.Tag = item;
                    viewitem.SubItems.Add(strs[3]);//日期
                    viewitem.SubItems.Add(gettradestatus(strs[2]));//交易状态
                    viewitem.SubItems.Add("");//查询交易结果
                    viewitem.SubItems.Add(strs[5]);//对应交易出参
                    list.Add(viewitem);
                }
                else
                {
                    var viewitem = new ListViewItem("");//交易流水号
                    viewitem.SubItems.Add("");//日期
                    viewitem.SubItems.Add("");//交易状态
                    viewitem.SubItems.Add(callparam.OutData);//查询交易结果
                    viewitem.SubItems.Add("");//对应交易出参
                    list.Add(viewitem);
                }
                listView1.Items.Clear();
                listView1.Items.AddRange(list.ToArray());
            }
        }
    }
}
